/**
 * 
 */
package de.guidoludwig.jtm.client.artists;

import java.text.FieldPosition;
import java.text.Format;
import java.text.ParsePosition;

import de.guidoludwig.jtm.domain.Artist;
import de.guidoludwig.jtm.util.StringUtil;

/**
 * @author guido
 * Read Only Format to convert an Artist into a beautiful HTML String
 */
public class ArtistHTMLFormat extends Format {
	
	public static final ArtistHTMLFormat INSTANCE = new ArtistHTMLFormat();

	@Override
	public StringBuffer format(Object obj, StringBuffer toAppendTo,
			FieldPosition pos) {
		if (obj == null) {
			return toAppendTo;
		}
		Artist a = (Artist)obj;
		toAppendTo.append("<html><h1>" + a.getName() + "</h1>" + toHTMLLines(a.getRemarks()));
		return toAppendTo;
	}

	private String toHTMLLines(String remarks) {
		if (StringUtil.isBlank(remarks)) {
			return remarks;
		}
		return remarks.replaceAll("\n", "<br/>");
	}

	@Override
	public Object parseObject(String source, ParsePosition pos) {
		throw new UnsupportedOperationException();
	}

}
